﻿namespace QuailDashboard.View.Models
{
    /// <summary>
    /// Wraps the IsProcessing flag
    /// </summary>
    public class IsProcessingStateModel : Model
    {
        private int _processingCounter;
        private string _processingText;

        /// <summary>
        /// Gets a value indicating whether the data on the page Is Refreshing
        /// </summary>
        public bool IsProcessing
        {
            get
            {
                return _processingCounter > 0;
            }
        }

        /// <summary>
        /// Gets or sets the processing text
        /// </summary>
        public string ProcessingText
        {
            get
            {
                return _processingText;
            }

            set
            {
                _processingText = value;
                NotifyPropertyChanged("ProcessingText");
            }
        }

        /// <summary>
        /// Indicates that a process is in process (haha)
        /// </summary>
        /// <param name="text">message to display while processing</param>
        public void IncProcessing(string text)
        {
            if (text != null)
                ProcessingText = text;

            _processingCounter++;

            if (_processingCounter == 1)
                NotifyPropertyChanged("IsProcessing");
        }

        /// <summary>
        /// Indicates that a process is complete
        /// </summary>
        public void DecProcessing()
        {
            _processingCounter--;

            if (_processingCounter == 0)
                NotifyPropertyChanged("IsProcessing");
        }

    }
}
